package cn.tedu;

import java.util.*;

/*本类用于练习集合(Collections)
* sort  相当于升序
* Shuffle  相当于洗牌,随机
* reverse  相当于逆序
* */
public class Object1 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(12);
        list.add(4);
        list.add(3);
        list.add(5);
        Collections.sort(list);
        System.out.println("list = "+list);
        System.out.println("==================");
        Collections.reverse(list);
        System.out.println("list = "+list);
        Collections.addAll(list,9,20,56);
        Collections.shuffle(list);
        System.out.println("list"+list);


        List<String> list2 = Arrays.asList("tom","kobe","jordan","tracy","westbook","yaoming","ace","stephen");
        Collections.sort(list2);
        System.out.println("list2 = "+list2);
        Collections.sort(list2,new Comparator<String>(){
            public int compare(String o1,String o2){
                return o2.charAt(0)-o1.charAt(0);
            }
        });
        System.out.println("list2 = "+list2);
        Collections.sort(list2,(o1, o2) ->{return o2.charAt(o2.length()-1)-o1.charAt(o1.length()-1);} );
    }
}
